package org.baixin.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.baixin.core.Page;
import org.baixin.exception.AppException;
import org.baixin.manager.BaseManager;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * 
 * 控制器基类
 * 
 * @author slaton.wu@gmail.com
 * @version 1.0
 * @created 2011-6-11 下午07:38:25
 */
@ParentPackage("pm-default")
public abstract class BaseAction<T,EntityManager extends BaseManager<T, Long>> extends ActionSupport implements
		ServletRequestAware, ServletResponseAware {

	protected Integer pageSize = 20;

	protected Page<T> page = new Page<T>(pageSize);

	public final static String LOGIN = "login";

	protected HttpServletRequest request;

	protected HttpServletResponse response;
	
	protected EntityManager entityManager;
	
	public static String LIST = "list"; 
	
	/**
	 * 操作提示
	 */
	public String operate = "0";
	
	/**
	 * 实体对象主键
	 */
	protected String ids;

	/**
	 * @param response
	 * @see org.apache.struts2.interceptor.ServletResponseAware#setServletResponse(javax.servlet.http.HttpServletResponse)
	 */
	public void setServletResponse(HttpServletResponse response) {
		
		this.response = response;
	}

	/**
	 * @param request
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
	 */
	public void setServletRequest(HttpServletRequest request) {

		this.request = request;
	}
	
	//-- CRUD Action函数 --//
	/**
	 * Action函数,显示Entity列表界面.
	 * 建议return SUCCESS.
	 */
	public abstract String list() throws AppException;

	/**
	 * Action函数,显示新增或修改Entity界面.
	 * 建议return INPUT.
	 */
	@Override
	public abstract String input() throws AppException;

	/**
	 * Action函数,新增或修改Entity. 
	 * 建议return RELOAD.
	 */
	public abstract String save() throws AppException;

	/**
	 * Action函数,删除Entity.
	 * 建议return RELOAD.
	 */
	public abstract String delete() throws AppException;

	/**
	 * 设置 entityManager 的值
	 * @param entityManager
	 */
	public abstract void setEntityManager(EntityManager entityManager);

	/**
	 * 返回 page 的值
	 * @return page
	 */
	
	public Page<T> getPage() {
		return page;
	}

	/**
	 * 设置 page 的值
	 * @param page
	 */
	
	public void setPage(Page<T> page) {
		this.page = page;
	}


	/**
	 * 返回 ids 的值
	 * @return ids
	 */
	
	public String getIds() {
		return ids;
	}

	/**
	 * 设置 ids 的值
	 * @param ids
	 */
	
	public void setIds(String ids) {
		this.ids = ids;
	}

	/**
	 * 返回 operate 的值
	 * @return operate
	 */
	
	public String getOperate() {
		return operate;
	}

	/**
	 * 设置 operate 的值
	 * @param operate
	 */
	
	public void setOperate(String operate) {
		this.operate = operate;
	}
	
	
	
}
